package day13;

import java.util.stream.IntStream;

/**
 * yield方法可以切换线程的状态，把当前线程从Running变为Runnable
 */
public class YieldDemo {

    public static void main(String[] args) {
        IntStream.range(0, 2)
                .mapToObj(YieldDemo::create)
                .forEach(Thread::start);
    }

    public static Thread create(int index) {
        return new Thread(() -> {
//            if (index == 0)
//                Thread.yield();
            System.out.println(index);
        });
    }

}
